//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.hustcad.plm.pdm.form.controller;

import com.alibaba.fastjson.JSONObject;
import com.hustcad.plm.basic.log.LogEventEnum;
import com.hustcad.plm.basic.util.TyplmViewConfigUtil;
import com.hustcad.plm.pdm.audit.util.TyplmAuditLogUtil;
import com.hustcad.plm.pdm.common.model.dto.search.SearchColumnDTO;
import com.hustcad.plm.pdm.common.model.vo.search.SearchTypeVO;
import com.hustcad.plm.pdm.container.model.vo.product.ContainerInfoVo;
import com.hustcad.plm.pdm.container.service.TyplmPdmContainerService;
import com.hustcad.plm.pdm.doc.vo.PdmDocFormData;
import com.hustcad.plm.pdm.file.model.dto.QueryPdmFileListByConditionDTO;
import com.hustcad.plm.pdm.file.model.vo.PdmFileListByConditionVO;
import com.hustcad.plm.pdm.form.model.dto.FormParamDTO;
import com.hustcad.plm.pdm.form.model.dto.QueryObjectIbaAttrValueDTO;
import com.hustcad.plm.pdm.form.model.vo.PdmForm;
import com.hustcad.plm.pdm.form.model.vo.PdmFormColumn;
import com.hustcad.plm.pdm.form.model.vo.PdmFormData;
import com.hustcad.plm.pdm.form.service.TyplmDynamicFormService;
import com.hustcad.plm.pdm.form.util.TyplmDynamicFormUtil;
import com.hustcad.plm.pdm.partbom.vo.PdmPartFormData;
import com.hustcad.plm.pdm.partbom.vo.PdmPartTableData;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.audit.AuditLogDO;
import com.ty.basic.handler.exceptionhandler.exception.ResponseCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.TyException;
import com.ty.basic.response.ResponseResult;
import com.ty.basic.utils.ArgumentUtils;
import com.ty.basic.vo.AttributeVO;
import io.swagger.annotations.ApiOperation;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/rest/v1/dynamicForm"})
public class TyplmDynamicFormController {
    @Resource
    private TyplmDynamicFormService typlmDynamicFormService;
    @Resource
    TyplmPdmContainerService typlmPdmContainerService;

    public TyplmDynamicFormController() {
    }

    @GetMapping({"/getPdmFormWithDataByType"})
    @ApiOperation(
            value = "获取新建表单格式(默认系统数据)",
            notes = "根据type和vo返回新建表单（带部分系统数据）",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getPdmFormWithDataByType(String type, String partView, String containerOid, String containerOtype, String formLabel, String voName) {
        try {
            Class aClass = TyplmViewConfigUtil.getVoClassByVoName(voName);
            return ResponseResult.success(this.typlmDynamicFormService.getPdmFormWithData(type, partView, containerOid, containerOtype, aClass, formLabel));
        } catch (Throwable var8) {
            try {
                throw var8;
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @GetMapping({"/getIbaByClassification"})
    @ApiOperation(
            value = "获取分类的扩展属性",
            notes = "获取分类的扩展属性",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getIbaByClassification(String oid) {
        return ResponseResult.success(this.typlmDynamicFormService.getIbaByClassification(oid));
    }

    @PostMapping({"/getIbaByIdentifierEntity"})
    @ApiOperation(
            value = "根据IdentifierEntity获取iba",
            notes = "根据IdentifierEntity获取iba",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getIbaByIdentifierEntity(@RequestBody IdentifierEntity entity) {
        return ResponseResult.success(this.typlmDynamicFormService.getIbaByIdentifierEntity(entity));
    }

    @PostMapping({"/dealImportedForm"})
    @ApiOperation(
            value = "导入form配置数据处理",
            notes = "导入form配置数据处理",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> dealImportedForm(@RequestBody PdmForm pdmForm) {
        AuditLogDO auditLogDO;
        try {
            PdmForm form = this.typlmDynamicFormService.dealImportedForm(pdmForm);
            auditLogDO = new AuditLogDO();
            auditLogDO.setDescription("导入属性配置数据");
            TyplmAuditLogUtil.info(auditLogDO, LogEventEnum.IMPORT);
            return ResponseResult.success(form);
        } catch (Exception var4) {
            auditLogDO = new AuditLogDO();
            auditLogDO.setDescription("导入属性配置数据");
            TyplmAuditLogUtil.errorInfo(LogEventEnum.IMPORT, auditLogDO, var4);
            throw var4;
        }
    }

    @GetMapping({"/deleteFormClass"})
    @ApiOperation(
            value = "通过class删除Form属性JSON数据",
            notes = "通过class删除Form属性JSON数据",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult deleteFormClass(String voName, String partView, String formLabel, String type) throws ClassNotFoundException {
        AuditLogDO auditLogDO;
        try {
            Class aClass = TyplmViewConfigUtil.getVoClassByVoName(voName);
            auditLogDO = new AuditLogDO();
            auditLogDO.setDescription("清除属性分组配置");
            TyplmAuditLogUtil.info(auditLogDO, LogEventEnum.DELETE_OBJECT);
            this.typlmDynamicFormService.deleteFormClass(aClass, partView, formLabel, type, voName);
            return ResponseResult.success();
        } catch (Exception var7) {
            auditLogDO = new AuditLogDO();
            auditLogDO.setDescription("清除属性分组配置");
            TyplmAuditLogUtil.errorInfo(LogEventEnum.DELETE_OBJECT, auditLogDO, var7);
            throw var7;
        }
    }

    @PostMapping({"/getIbaByLogicalIdentifier"})
    @ApiOperation(
            value = "根据类型逻辑标识符获取扩展属性",
            notes = "根据类型逻辑标识符获取扩展属性",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getIbaByLogicalIdentifier(@RequestBody String logicalIdentifier) {
        if (StringUtils.isBlank(logicalIdentifier)) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.ACC_PARAMETER_IS_NULL, new String[]{"logicalIdentifier"});
        }

        return ResponseResult.success(this.typlmDynamicFormService.getIbaByLogicalIdentifier(logicalIdentifier));
    }

    @GetMapping({"/getPdmFormByType"})
    @ApiOperation(
            value = "获取表单格式",
            notes = "据type和vo返回表单格式",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getPdmFormByType(String type, String partView, String formLabel, String voName) {
        try {
            Class aClass = TyplmViewConfigUtil.getVoClassByVoName(voName);
            if (TyplmDynamicFormUtil.checkNeedDealViewByVoName(voName)) {
                type = type + ";" + partView;
            }

            return ResponseResult.success(this.typlmDynamicFormService.getPdmForm(aClass, type, formLabel, partView));
        } catch (Throwable var6) {
            try {
                throw var6;
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @PostMapping({"/updatePdmForm"})
    @ApiOperation(
            value = "更新用户自定义的属性展示form",
            notes = "更新用户自定义的属性展示form",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult updatePdmForm(@RequestBody PdmForm pdmForm) {
        try {
            this.typlmDynamicFormService.updatePdmForm(pdmForm);
            return ResponseResult.success();
        } catch (Throwable var3) {
            try {
                throw var3;
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @PostMapping({"/queryDocForm"})
    @ApiOperation(
            value = "获取form格式文档详情",
            notes = "获取form格式文档详情",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmDocFormData> queryDocForm(@RequestBody JSONObject reqJson) {
        ArgumentUtils.checkArgumentNull(reqJson.getBigInteger("oid"), "对象id为空");
        ArgumentUtils.checkArgumentNull(reqJson.getString("oType"), "对象类型为空");
        return ResponseResult.success(this.typlmDynamicFormService.queryDocForm(reqJson.getBigInteger("oid"), reqJson.getString("oType")));
    }

    @GetMapping({"/queryPartForm"})
    @ApiOperation(
            value = "查询零部件详情(form格式)",
            notes = "查询零部件详情(form格式)",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmPartFormData> queryPartForm(@RequestParam BigInteger oid, @RequestParam String oType, @RequestParam String partView, @RequestParam(required = false,defaultValue = "1") String isQueryDetail, @RequestParam(required = false) String partTypeOid) {
        ArgumentUtils.checkArgumentNull(oid, "对象id为空");
        ArgumentUtils.checkArgumentNull(oType, "对象类型为空");
        return ResponseResult.success(this.typlmDynamicFormService.queryPartForm(oid, oType, partView, isQueryDetail, partTypeOid));
    }

    @GetMapping({"/queryPartFormWithoutDetail"})
    @ApiOperation(
            value = "查询零部件form，排除详情",
            notes = "查询零部件form，排除详情",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmPartFormData> queryPartFormWithoutDetail(@RequestParam String partTypeOid, @RequestParam String partView) {
        ArgumentUtils.checkArgumentNull(partTypeOid, "对象类型id为空");
        return ResponseResult.success(this.typlmDynamicFormService.queryPartFormWithoutDetail(partTypeOid, partView));
    }

    @GetMapping({"/queryPartTable"})
    @ApiOperation(
            value = "查询零部件详情(table格式)",
            notes = "查询零部件详情(table格式)",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmPartTableData> queryPartTable(@RequestParam BigInteger oid, @RequestParam String oType) {
        ArgumentUtils.checkArgumentNull(oid, "对象id为空");
        ArgumentUtils.checkArgumentNull(oType, "对象类型为空");
        return ResponseResult.success(this.typlmDynamicFormService.queryPartTable(oid, oType));
    }

    @GetMapping({"/uploadPdmPartTableDataGenericTypeAndCollapsible"})
    @ApiOperation(
            value = "更新零部件的表单的可配置模块可折叠字段信息",
            notes = "更新零部件的表单的可配置模块可折叠字段信息",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmPartTableData> uploadPdmPartTableDataGenericTypeAndCollapsible() {
        this.typlmDynamicFormService.uploadPdmPartTableDataGenericTypeAndCollapsible();
        return ResponseResult.success();
    }

    @GetMapping({"/newGetPdmFormByType"})
    @ApiOperation(
            value = "获取表单格式",
            notes = "据type和vo返回表单格式",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> newGetPdmFormByType(String type, String partView, String formLabel, String voName, String classificationOid) {
        try {
            Class aClass = TyplmViewConfigUtil.getVoClassByVoName(voName);
            PdmForm pdmForm = this.typlmDynamicFormService.getPdmForm(aClass, type, formLabel, partView, classificationOid);
            this.typlmDynamicFormService.processingRules(pdmForm);
            return ResponseResult.success(pdmForm);
        } catch (Throwable var8) {
            try {
                throw var8;
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @GetMapping({"/newGetPdmFormByTypeAndViewType"})
    @ApiOperation(
            value = "获取表单格式",
            notes = "据type和vo返回表单格式",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> newGetPdmFormByTypeAndViewType(String type, String partView, String formLabel, String voName, String viewType, String classificationOid) {
        try {
            Class aClass = TyplmViewConfigUtil.getVoClassByVoName(voName, viewType);
            PdmForm pdmForm = this.typlmDynamicFormService.getPdmForm(aClass, type, formLabel, partView, classificationOid);
            if (ObjectUtils.isNotEmpty(pdmForm)) {
                pdmForm.setViewType(viewType);
            }

            this.typlmDynamicFormService.processingRules(pdmForm);
            return ResponseResult.success(pdmForm);
        } catch (Throwable var9) {
            try {
                throw var9;
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @GetMapping({"/newGetPdmFormWithDataByType"})
    @ApiOperation(
            value = "获取新建表单格式(默认系统数据)",
            notes = "根据type和vo返回新建表单（带部分系统数据）",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> newGetPdmFormWithDataByType(String type, String partView, String containerOid, String containerOtype, String formLabel, String voName, String classificationOid) {
        try {
            Class aClass = TyplmViewConfigUtil.getVoClassByVoName(voName);
            PdmForm pdmForm=this.typlmDynamicFormService.getPdmFormWithData(type, partView, containerOid, containerOtype, aClass, formLabel, classificationOid);

            if("样机物料采购BOM".equals(type)){
                ContainerInfoVo containerInfoVo=typlmPdmContainerService.getContainerInfoVo(new BigInteger(containerOid), containerOtype);
                Map<String, List<String>> attr=containerInfoVo.getIbaAttributeMap();
                String code="";
                if(attr.containsKey("产品代号")){
                    List<String> codeList=attr.get("产品代号");
                    if(codeList.size()>0){
                        code=codeList.get(0);
                    }
                }

                List<PdmFormColumn> pdmFormColumns=pdmForm.getFormData();
                for(int i=0;i<pdmFormColumns.size();i++){
                    if("产品代号".equals(pdmFormColumns.get(i).getName())){
                        pdmFormColumns.get(i).setValue(code);
                        break;
                    }
                }
            }
            return ResponseResult.success(pdmForm);
        } catch (Throwable var9) {
            try {
                throw var9;
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @GetMapping({"/newQueryPartFormWithoutDetail"})
    @ApiOperation(
            value = "查询零部件form，排除详情",
            notes = "查询零部件form，排除详情",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmPartFormData> newQueryPartFormWithoutDetail(String partTypeOid, String partView, String classificationOid) {
        ArgumentUtils.checkArgumentNull(partTypeOid, "对象类型id为空");
        return ResponseResult.success(this.typlmDynamicFormService.newQueryPartFormWithoutDetail(partTypeOid, partView, classificationOid));
    }

    @PostMapping({"/newQueryDocForm"})
    @ApiOperation(
            value = "获取form格式文档详情",
            notes = "获取form格式文档详情",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmDocFormData> newQueryDocForm(@RequestBody JSONObject reqJson) {
        ArgumentUtils.checkArgumentNull(reqJson.getBigInteger("oid"), "对象id为空");
        ArgumentUtils.checkArgumentNull(reqJson.getString("oType"), "对象类型为空");
        return ResponseResult.success(this.typlmDynamicFormService.newQueryDocForm(reqJson.getBigInteger("oid"), reqJson.getString("oType"), reqJson.getString("classificationOid")));
    }

    @PostMapping({"/getQueryFormWithoutDetail"})
    @ApiOperation(
            value = "获取form格式详情",
            notes = "获取form格式详情",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmFormData> getQueryFormWithoutDetail(@RequestBody FormParamDTO formParamDTO) {
        try {
            return ResponseResult.success(this.typlmDynamicFormService.getQueryFormWithoutDetail(formParamDTO));
        } catch (Throwable var3) {
            try {
                throw var3;
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @GetMapping({"/getBasicProperties"})
    @ApiOperation(
            value = "获取基本属性选择框,用于属性分组对象引用",
            notes = "获取基本属性选择框,用于属性分组对象引用",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<Map<String, String>> getBasicProperties() {
        return ResponseResult.success(this.typlmDynamicFormService.getBasicProperties());
    }

    @PostMapping({"/getObjectIbaAttrValue"})
    @ApiOperation(
            value = "查询对象扩展属性",
            notes = "查询对象扩展属性",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<Map<String, List<AttributeVO>>> getObjectIbaAttrValue(@RequestBody QueryObjectIbaAttrValueDTO queryObjectIbaAttrValueDTO) {
        return ResponseResult.success(this.typlmDynamicFormService.getObjectIbaAttrValue(queryObjectIbaAttrValueDTO));
    }

    @PostMapping({"/queryPdmFileListByCondition"})
    @ApiOperation(
            value = "查询属性分组列表",
            notes = "查询属性分组列表",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<List<PdmFileListByConditionVO>> queryPdmFileListByCondition(@RequestBody QueryPdmFileListByConditionDTO queryObjectIbaAttrValueDTO) {
        return ResponseResult.success(this.typlmDynamicFormService.queryPdmFileListByCondition(queryObjectIbaAttrValueDTO));
    }

    @GetMapping({"/getBatchAddPartForm"})
    @ApiOperation(
            value = "批量新建零部件表单",
            notes = "批量新建零部件表单",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getBatchAddPartForm(String tableViewName) {
        ArgumentUtils.checkArgumentNull(tableViewName, "视图表Id为空");
        return ResponseResult.success(this.typlmDynamicFormService.getBatchAddPartForm(tableViewName));
    }

    @PostMapping({"/getIbaAndConstraintsByType"})
    @ApiOperation(
            value = "通过类型或者分类查询IBA以及约束",
            notes = "通过类型或者分类查询IBA以及约束",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getIbaAndConstraintsByType(@RequestBody List<IdentifierEntity> objectList) {
        ArgumentUtils.checkArgumentNull(objectList, "类型或者分类为空");
        return ResponseResult.success(this.typlmDynamicFormService.getIbaAndConstraintsByType(objectList));
    }

    @PostMapping({"/getBatchAddPartColumn"})
    @ApiOperation(
            value = "获取视图管理批量新建动态列",
            notes = "获取视图管理批量新建动态列",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<List<SearchColumnDTO>> getBatchAddPartColumn(@RequestBody List<SearchTypeVO> list) {
        ArgumentUtils.checkArgumentNull(list, "类型或者分类为空");
        return ResponseResult.success(this.typlmDynamicFormService.getBatchAddPartColumn(list));
    }

    @GetMapping({"/getPdmFormByTypeIbaAndTableId"})
    @ApiOperation(
            value = "根据视图id以及类型扩展属性获取视图管理信息",
            notes = "获取部件全局替代视图字段",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getPdmFormByTypeIbaAndTableId(String tableid) {
        ArgumentUtils.checkArgumentNull(tableid, "视图表Id为空");
        return ResponseResult.success(this.typlmDynamicFormService.getPdmFormByTypeIbaAndTableId(tableid));
    }

    @GetMapping({"/getDynamicFormByTableViewName"})
    @ApiOperation(
            value = "通过视图标识获取表单",
            notes = "通过视图标识获取表单",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<PdmForm> getDynamicFormByTableViewName(String tableViewName) throws ClassNotFoundException {
        ArgumentUtils.checkArgumentNull(tableViewName, "视图表Id为空");
        return ResponseResult.success(this.typlmDynamicFormService.getDynamicFormByTableViewName(tableViewName));
    }

    @PostMapping({"/queryTableViewByTableOidAndParentTypeOid"})
    @ApiOperation(
            value = "根据父对象类型以及视图标识获取视图信息",
            notes = "通过视图标识获取表单",
            produces = "application/json; charset=utf-8"
    )
    public ResponseResult<Map<IdentifierEntity, PdmForm>> queryTableViewByTableOidAndParentTypeOid(@RequestBody JSONObject reqJson) {
        ArgumentUtils.checkArgumentNull(reqJson.getBigInteger("parentTypeOid"), "父对象oid为空");
        ArgumentUtils.checkArgumentNull(reqJson.getString("tableId"), "视图标识为空");
        return ResponseResult.success(this.typlmDynamicFormService.queryTableViewByTableOidAndParentTypeOid(reqJson.getBigInteger("parentTypeOid"), reqJson.getString("tableId")));
    }
}
